package com.qk.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.qk.common.PageResult;
import com.qk.dto.CourseDto;
import com.qk.entity.Course;
import com.qk.mapper.CourseMapper;
import com.qk.service.CourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class CourseServiceImpl implements CourseService {
    @Autowired
    private CourseMapper courseMapper;
    //课程列表
    @Override
    public PageResult<Course> courseList(CourseDto courseDto) {
        PageHelper.startPage(courseDto.getPage(),courseDto.getPageSize());
        List<Course> courseList=courseMapper.selectList(courseDto);
        Page<Course> p = (Page<Course>) courseList;
        return new PageResult<>(p.getTotal(),p.getResult());
    }
    //删除课程
    @Override
    public void delete(Integer id) {
        courseMapper.delete(id);
    }
    //添加课程
    @Override
    public void add(Course course) {
        course.setCreateTime(LocalDateTime.now());
        course.setUpdateTime(LocalDateTime.now());
        courseMapper.insert(course);
    }
    //根据id查询课程
    @Override
    public Course getByID(Integer id) {
        return courseMapper.selectByID(id);
    }
    //修改课程
    @Override
    public void upDate(Course course) {
        course.setUpdateTime(LocalDateTime.now());
        courseMapper.upDate(course);
    }
    //查询所有课程
    @Override
    public List <Course> allList(Course course) {
        return courseMapper.selectAllList();
    }
    //根据科目查询课程
    @Override
    public List<Course> subjectList(Integer subject) {
        return courseMapper.subjectList(subject);
    }
}
